package com.wen.common.enums;

import java.util.function.Function;

/**
 * 脱敏策略枚举
 * <p>
 *
 * @author liwen <devinlive@163.com>
 * @version 1.0
 * @since 2023/03/10 14:31
 */
public enum SensitiveStrategy {
    /**用户名*/
    USERNAME(s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),
    /**身份证*/
    ID_CARD(s -> s.replaceAll("(\\d{4})\\d{10}(\\w{4})", "$1****$2")),
    /**手机号*/
    PHONE(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
    /**邮箱*/
    EMAIL(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
    /**地址*/
    ADDRESS(s -> s.replaceAll("(\\S{3})\\S{2}(\\S*)\\S{2}", "$1****$2****"));

    private final Function<String, String> function;

    private SensitiveStrategy(Function<String, String> desensitizer) {
        this.function = desensitizer;
    }

    public Function<String, String> getDesensitizer() {
        return function;
    }
}
